package br.com.tcf.dao;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import br.com.tcf.Conexao.Connection;
import br.com.tcf.Conexao.DaoResource;
import br.com.tcf.entidades.Cardapio;
import br.com.tcf.entidades.Empresa;

public class CardapioDao extends DaoResource{
	private static Connection connection = new Connection();
	private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
	private Cardapio cardapio;

	private List<Cardapio> cardapios;
	public void grava_cardapio(Cardapio cardap){
		cardap.setVersao(cardap.getVersao()+1);
		try {
			cardap.setDt_atualizacao(new java.sql.Date (sdf.parse(sdf.format(new java.util.Date())).getTime()));
		} catch (ParseException e) {
			e.printStackTrace();
		}		
		super.saveOrUpdate(connection, cardap);
	}
	
	public void exclui_cardapio(Cardapio cadap){		
		super.delete(connection, cadap);
	}
	
	@SuppressWarnings("unchecked")
	public Cardapio listar_cardapio_empresa(Empresa empresa){
		List<Cardapio> card = super.select(connection, "FROM Cardapio where id_empresa = :id", "id", empresa);
		
		if(card.size() == 0){
			return null;
		}else{
			return card.get(0);
		}
	}
	
	public Cardapio getCardapio() {
		return cardapio;
	}

	public void setCardapio(Cardapio cardapio) {
		this.cardapio = cardapio;
	}

	public List<Cardapio> getCardapios() {
		return cardapios;
	}

	public void setCardapios(List<Cardapio> cardapios) {
		this.cardapios = cardapios;
	}
}
